from option import Option
import signals
import gtk
import gobject
import urllib
import re
import helpers
import gettext

_ = gettext.gettext

def check(widget):
	try:
		page = urllib.urlopen('http://cubeassistant.googlecode.com/svn/trunk/cubeassistant.pyw').read()
		ver = re.search('version=\'(.+)\'',page).groups()[0]
		message = "".join([_('Actual version'),': ',str(helpers.VER),'\n',_('Newest version'),': ',ver,'\n',_('Do you want to upgrade?')])
		dial = gtk.MessageDialog(message_format=message, buttons=gtk.BUTTONS_YES_NO)
		response = dial.run()
		dial.hide()
		if response == gtk.RESPONSE_YES:
			dial = gtk.MessageDialog(message_format=_('Sorry, it\'s still unimplemented'), buttons=gtk.BUTTONS_OK)
			dial.run()
			dial.hide()


	except:
		dial = gtk.MessageDialog(message_format=_('Connection couldn\'t be resolved'),buttons=gtk.BUTTONS_OK,type=gtk.MESSAGE_WARNING)
		dial.run()
		dial.hide()



def init():
	Option().windowMain.xml.get_widget('MenuUpdate').connect('activate',check)


def info():
	return {'name':'mod_updater',
			'author':'Michal Hordecki',
			'description':'Cube Assistant update checker and downloader.',
			}

def teardown():
	pass

